/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.db.mdm;

import com.db.mdm.hub.MDMHub;
import com.db.mdm.mdmrepo.MDMRepo;
import com.db.mdm.spoke.MDMSpoke;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

/**
 *
 * @author srkrishnan
 */
public class Main {

    public Main() {
        try {
            /*Load MDM configuration*/
            XMLConfiguration config = new XMLConfiguration("MDMConfig.xml");

            /*create Repository*/
            MDMRepo mdmRepo=new MDMRepo(config);
            mdmRepo.run();

            /*create MDM Hub*/
            MDMHub mdmHub=new MDMHub(config,mdmRepo.getRepoConnection());
            mdmHub.run();

            /*create Spokes*/
            for(int spokeindex=0;spokeindex<=config.getMaxIndex("spoke");spokeindex++)
            {
                System.out.println("name : "+config.getString("spoke("+spokeindex+").name"));
                MDMSpoke mdmSpoke=new MDMSpoke(config, spokeindex,mdmRepo.getRepoConnection());
                mdmSpoke.run();
            }

            /*MDMConnection mysqlconnHub = new MySQLConnection(config.getString("hub.host"), config.getString("hub.user"), config.getString("hub.pass"), config.getString("hub.db"), config.getInt("hub.port"));
            mysqlconnHub.connectDB();

            MDMConnection mysqlconnRepo = new MySQLConnection(config.getString("hub.repo.host"), config.getString("hub.repo.user"), config.getString("hub.repo.pass"), config.getString("hub.repo.db"), config.getInt("hub.repo.port"));
            mysqlconnRepo.connectDB();

            MySQLListner mysqllistenHub = new MySQLListner(mysqlconnHub,mysqlconnRepo,config);
            Thread mySQLListernerThread = new Thread(mysqllistenHub, "MySQL Listener");
            ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
            scheduler.scheduleWithFixedDelay(mySQLListernerThread, 0, 3, TimeUnit.SECONDS);*/
        } catch (ConfigurationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        

    }



    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        new Main();

    }
}
